package com.tywj.panda.customer.usercenter.settings

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.tywj.lib.core.common.extension.gone
import com.tywj.lib.core.common.extension.onClick
import com.tywj.lib.core.common.extension.visible
import com.tywj.lib.core.common.util.BarUtil
import com.tywj.lib.core.common.util.ResourcesUtil
import com.tywj.lib.route.RouteUtil
import com.tywj.panda.customer.common.api.CommonApi
import com.tywj.panda.customer.common.provider.IH5Service
import com.tywj.panda.customer.common.tool.LogoutTool
import com.tywj.panda.customer.common.view.base.MyBaseActivity
import com.tywj.panda.customer.usercenter.R
import com.tywj.panda.customer.usercenter.route.UserCenterRoute
import kotlinx.android.synthetic.main.user_activity_settings.*

/**
 * 设置
 */
@Route(path = UserCenterRoute.USER_SETTINGS)
class SettingsActivity : MyBaseActivity() {

    override fun getLayoutID(): Int = R.layout.user_activity_settings

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        BarUtil.setStatusBarColor(this, ResourcesUtil.getColor(R.color.common_white))
        BarUtil.setStatusBarLightMode(this.window, true)

        if (LogoutTool.isLogin) {
            visible(tvLogout)
        } else {
            gone(tvLogout)
        }
    }

    override fun initListener() {
        super.initListener()

        flArgeement.onClick {

            RouteUtil.getServiceProvider(IH5Service::class.java)
                ?.toH5Activity(
                    indexUrl = CommonApi.H5_URL + "pages/userAgreement/userAgreement",
                    title = "用户协议",
                    titleBgColor = ResourcesUtil.getColor(R.color.common_black_1F),
                    isShowCloseView = false
                )?.navigation(this)

        }
        flAbout.onClick {
            UserCenterRoute.toAboutUs().navigation(this)
        }

        tvLogout.onClick {
            TipsDialog.Builder(this)
                .setTipDetails(ResourcesUtil.getString(R.string.user_center_confirm_logout))
                .setConfirmListener {
                    logout()
                }
                .show()
        }
    }

    private fun logout() {
        LogoutTool.logout()
    }
}